package com.problem.leetcode;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * @author didi
 * @DESCRIPTION
 * @create 2019-04-30 14:15
 **/

public class Problem970 {
    public List<Integer> powerfulIntegers(int x, int y, int bound) {
        HashSet<Integer> hashSet = new HashSet<>();
        int              xIndex  = 0, yIndex;
        for (; ; xIndex++) {
            yIndex = 0;
            for (; ; yIndex++) {
                int xValue = (int) Math.pow(x, xIndex);
                int yValue = (int) Math.pow(y, yIndex);

                if ((xValue + yValue) <= bound) {
                    hashSet.add(xValue + yValue);
                } else {
                    break;
                }
            }
            if (xIndex > 0 && yIndex == 0) {
                break;
            }

        }
        List<Integer> list = new ArrayList<>(hashSet.size());
        list.addAll(hashSet);
        return list;
    }
}
